import time

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By

from com.lucksoft.fixedassets.login import assetsLogin


# 固定资产台账增删改查
def addAssets():
    driver = assetsLogin.login('http://10.10.10.50:32060/', 'gzadmin', 'Gdjt@2021')

    # # 打开地址
    # driver.get('http://10.10.10.50:32060/')
    # # 输入用户名密码
    # driver.find_element(By.ID, 'username').send_keys('gzadmin')
    # driver.find_element(By.ID, 'password').send_keys('Gdjt@2021')
    # driver.find_element(By.XPATH, '//button').click()
    # time.sleep(5)

    driver.find_element(By.XPATH, '//*[text()="固资管理子系统"]').click()
    driver.find_element(By.XPATH, '//*[text()="资产建账"]').click()
    time.sleep(2)
    # 新建资产录入

    driver.find_element(By.XPATH, '//button[@class="ant-btn ant-btn-primary"]').click()
    # driver.find_element_by_xpath('/html/body/div[4]/div/div/ul/li[1]/a')
    # driver.find_element(By.XPATH, '//*[text()="单条录入"]').click()
    driver.find_element_by_xpath('//a[text()="单条录入"]').click()
    time.sleep(2)

    # 基本信息
    driver.find_element_by_id('sassetnm').send_keys('公司资产')
    driver.execute_script('arguments[0].click();', driver.find_element_by_id('sassetclassscc'))
    driver.find_element_by_xpath('//li[text()="电子信息类"]').click()
    driver.find_element_by_xpath('//li[text()="电子计算机"]').click()

    driver.execute_script('arguments[0].click();',
                          driver.find_element_by_xpath('//*[@id="ssofthardwaremarkDic"]/div/div/div[1]'))
    driver.find_element_by_xpath('//li[text()="普通设备"]').click()

    driver.execute_script('arguments[0].click();',
                          driver.find_element_by_xpath('//*[@id="sassetztDic"]/div/div/div[1]'))
    # driver.execute_script('arguments[0].click();',driver.find_element_by_xpath('//div[@class="ant-select-selection__placeholder"]'))
    driver.find_element_by_xpath('//li[text()="自持类资产"]').click()

    driver.find_element_by_id('sassetmodel').send_keys('GB-2022111002')

    driver.find_element_by_id('sassetspec').send_keys('GB-2022111002')

    driver.find_element_by_id('sassetpaymentcode').send_keys('GB-2022111002')

    # driver.execute_script('arguments[0].click();',
    #                       driver.find_element_by_class_name('ant-select-selection__placeholder'))

    driver.execute_script('arguments[0].click();',
                          driver.find_element_by_xpath('//*[@id="sassetcategoryDic"]/div/div/div[1]'))
    driver.find_element_by_xpath('//li[text()="生产用"]').click()

    driver.find_element_by_id('ssnno').send_keys('GB-2022111002')

    driver.find_element_by_id('snote').send_keys('这是个简单的资产简述')

    # 使用信息
    driver.execute_script('arguments[0].click();',
                          driver.find_element_by_xpath(
                              '//*[@id="form2"]/div[2]/div[1]/div/div[2]/div/span/div/span/span/span[1]/span'))
    driver.find_element_by_xpath('//span[text()="马鞍山工厂"]').click()

    # driver.find_element_by_id('iuseterm').send_keys('24')

    # driver.execute_script('arguments[0].click();',
    #                       driver.find_element_by_xpath('//*[@id="form2"]/div[2]/div[4]/div/div[2]/div/span/div/span/div/i/svg'))
    # menu = driver.find_element_by_xpath('//*[@id="sgkdeptnm"]/div/div/div[1]')  # 定位鼠标要悬停的元素
    menu = driver.find_element_by_xpath('//*[@id="form2"]/div[2]/div[4]/div/div[2]/div/span/div/span/div/i')
    mouse = ActionChains(driver)
    mouse.click(menu).perform()

    # driver.find_element_by_xpath('//*[@id="sgkdeptnm"]/div/div/div[1]').send_keys('安全技术部')
    # mouse.move_to_element(menu).perform()  # 鼠标悬停到定位元素上

    # driver.find_element_by_xpath('//*[@id="sgkdeptnm"]/div/div/div[1]').send_keys('安全技术部')

    # driver.find_element_by_xpath('//*[@id="form2"]/div[2]/div[7]/div/div[2]/div/span/div/span/div/i/svg/path[2]').click()
    driver.find_element_by_xpath('//input[@placeholder="请搜索"]').send_keys('安全技术部')
    time.sleep(1)
    driver.find_element_by_xpath(
        '//*[@id="root"]/div[2]/div/div[2]/div/div[2]/div[2]/div/div/div/div/div[2]/div[3]/div').click()
    # driver.find_element_by_xpath('//button[@class="ant-btn gutter ant-btn-primary"]').click()
    driver.execute_script('arguments[0].click();',
                          # driver.find_element_by_xpath('//button[@class="ant-btn gutter ant-btn-primary"]'))
                          driver.find_element_by_xpath(
                              '//*[@id="root"]/div[2]/div/div[2]/div/div[2]/div[2]/div/div/div/div/div[2]/div[2]/button[2]/span'))

    time.sleep(1)

    menu = driver.find_element_by_xpath('//*[@id="form2"]/div[2]/div[5]/div/div[2]/div/span/div/span/div/i')
    mouse = ActionChains(driver)
    mouse.click(menu).perform()

    # driver.find_element_by_xpath('//*[@id="form2"]/div[2]/div[8]/div/div[2]/div/span/div/span/div/i/svg/path[2]').click()
    driver.find_element_by_xpath('//input[@placeholder="请搜索"]').send_keys('安全技术部')
    time.sleep(2)
    driver.find_element_by_xpath(
        '//*[@id="root"]/div[3]/div/div[2]/div/div[2]/div[2]/div/div/div/div/div[2]/div[3]/div').click()
    # driver.find_element_by_xpath('//*[text()="确定"]').click()
    driver.execute_script('arguments[0].click();', driver.find_element_by_xpath(
        '//*[@id="root"]/div[3]/div/div[2]/div/div[2]/div[2]/div/div/div/div/div[2]/div[2]/button[2]/span'))
    time.sleep(1)
    driver.find_element_by_id('sposdescribe').send_keys('这是个详细的位置描述')

    # driver.find_element_by_xpath('//*[@id="susernm"]/div/div/div[1]').send_keys('夏小天')

    # 购入信息
    # driver.execute_script('arguments[0].click();',
    #                       driver.find_element_by_xpath('//*[@id="sassetsourcetypeDic"]/div/div/div[1]'))

    menu = driver.find_element_by_xpath('//*[@id="sassetsourcetypeDic"]/div/div/div[1]')
    mouse = ActionChains(driver)
    mouse.click(menu).perform()

    driver.find_element_by_xpath('//li[text()="自建"]').click()

    driver.find_element_by_id('scontractno').send_keys('GB-2022111002')
    driver.find_element_by_id('sassetsourceno').send_keys('GB-2022111002')

    driver.find_element_by_id('soano').send_keys('GB-2022111002')

    driver.find_element_by_id('iassetmoneyeq').send_keys('20000')

    # 厂商信息
    driver.find_element_by_id('smanufacturer').send_keys('天天科技')

    driver.find_element_by_id('ssnno').send_keys('GB-2022111002')
    driver.find_element_by_id('suppliernm').send_keys('天天科技电子商品供应链')
    driver.find_element_by_id('supplierphone').send_keys('18934541245')

    # driver.find_element_by_xpath('//button[text()="保存"]').click()
    driver.execute_script('arguments[0].click();',
                          driver.find_element_by_xpath(
                              '//*[@id="root"]/div/div/div[2]/div/div[2]/div[2]/div/div/div/div[2]/div/div/div/div[1]/div/div[2]/div/div[2]/span/button'))
    # driver.execute_script('arguments[0].click();',
    #                       driver.find_element_by_xpath('//button[text()="保存"'))
    # driver.find_element_by_xpath('//button[@class="ant-btn ant-btn-primary"]').click()
    # driver.execute_script('arguments[0].click();',
    #                       driver.find_element_by_xpath('//button[@class="ant-btn ant-btn-primary"]'))


if __name__ == '__main__':
    addAssets()
    time.sleep(3)
